package com.efast.dmom.mgmt.controller.les;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.efast.cafe.framework.bean.ResultBean;
import com.efast.dmom.mgmt.entity.les.TtMmKanbanscanMri;
import com.efast.dmom.mgmt.service.les.TtMmKanbanscanMriService;
import com.efast.dmom.mgmt.utils.Assist;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 扫描看板需求组织 tt_mm_kanbanscan_mri---此表数据仅针对RF端的扫描看板卡需求 
 * 此页面仅能查出RF端扫描的需求，不能查出客户端手工组织的需求
 * 也就时说仅能查tt_mm_kanbanscan_mri的数据，不能查tt_mm_manual_mri的数据
 * <p>
 * 业务逻辑 与 手工上线指示单组织 一样
 *
 * @author Administrator
 */
@Controller
@RequestMapping(value = "/ttMmKanbanscanMri")
@Api(description = "上线指示单创建--针对RF端的扫描看板卡需求")
public class TtMmKanbanscanMriController {

    @Autowired
    private TtMmKanbanscanMriService ttMmKanbanscanMriService;

    /**
     * 【查询需求数据】
     */
    @ApiOperation(value = "查询需求数据", httpMethod = "POST", notes = "查tt_mm_kanbanscan_mri的数据")
    @RequestMapping(value = "/queryAll", method = RequestMethod.POST)
    public @ResponseBody
    ResultBean queryInfoByPullNo() {
        ResultBean result = new ResultBean(true, "'");
        // 物料需求信息状态((0;未组织，1已组织，2组织失败)
        List<TtMmKanbanscanMri> list = ttMmKanbanscanMriService
                .selectTtMmKanbanscanMri(new Assist(Assist.andEq("tt_mm_kanbanscan_mri.mri_status", "0")));
        result.setObject(list);
        return result;
    }

    /**
     * 组单生成上线指示单时，根据工厂、车间、路径分组产生单据，确保同一工厂、车间、路径下的需求在同一单据上， 方便配送人员直接按照配置的路线送货，提高效率
     * 单据包含头和子信息，产生单据的同时，产生历史记录信息，同时产生对应的出库订单
     */
    @SuppressWarnings("unchecked")
    @ApiOperation(value = "确认组单", httpMethod = "POST", notes = "请求参数==>{\"pullUnitNo\":[{\"pullUnitNo\":\"AS002\"}]}")
    @RequestMapping(value = "/confirmBill", method = RequestMethod.POST)
    public @ResponseBody
    ResultBean confirmBill(@RequestBody Map<String, Object> map) {
        ResultBean result = new ResultBean(true, "'");
        List<Map<String, Object>> ttMmManualMriEmptyBean = (List<Map<String, Object>>) map.get("pullUnitNo");
        ttMmKanbanscanMriService.confirmBill(ttMmManualMriEmptyBean);
        result.setMessage("组单成功");
        return result;
    }

}
